/*
 * @Desc:
 * @author cheegon
 * @date 2022/2/8  10:39
**/


import { curr_evn } from '@/config/envConfig'

/**
 * 头
 * @type {string}
 */
const KEY_HEAD = `blog_${ curr_evn.envName }_`

const KEY_SEARCH_IDS = KEY_HEAD + 'search_ids'
/**
 * 资源信息
 * @type {string}
 */
const KEY_MEMBER_INFO = KEY_HEAD + 'member_info'
/**
 * 设置
 * @type {string}
 */
const KEY_SETTING_INFO = KEY_HEAD + 'setting_info'
/**
 * 用户信息
 */
const KEY_USER_INFO = KEY_HEAD + 'user_info'

/**
 *
 * @type {string}
 */
const KEY_SELECT_CHECK_LIST = KEY_HEAD + 'select_check_list'

export const setSearchIds = (ids) => {
    localStorage.setItem(KEY_SEARCH_IDS, JSON.stringify(ids))
}
export const getSearchIds = () => {
    let s = localStorage.getItem(KEY_SEARCH_IDS)
    if (s) {
        return JSON.parse(s)
    }
    return s
}

export function setMemberInfo(info) {
    return localStorage.setItem(KEY_MEMBER_INFO, JSON.stringify(info))
}

export function getMemberInfo() {
    let s = localStorage.getItem(KEY_MEMBER_INFO)
    if (s) {
        return JSON.parse(s)
    }
    return s || {}
}

export function setSettingInfo(info) {
    return localStorage.setItem(KEY_SETTING_INFO, JSON.stringify(info))
}

export function getSettingInfo() {
    let s = localStorage.getItem(KEY_SETTING_INFO)
    if (s) {
        return JSON.parse(s)
    }
    return s || {}
}

export function removeMemberInfo() {
    return localStorage.removeItem(KEY_MEMBER_INFO)
}

export function setUserInfo(info) {
    return localStorage.setItem(KEY_USER_INFO, JSON.stringify(info))
}

export function getUserInfo() {
    let s = localStorage.getItem(KEY_USER_INFO)
    if (s) {
        return JSON.parse(s)
    }
    return s || {}
}

export function removeUserInfo() {
    return localStorage.removeItem(KEY_USER_INFO)
}

export const setSelectCheckList = (ids) => {
    localStorage.setItem(KEY_SELECT_CHECK_LIST, JSON.stringify(ids))
}
export const getSelectCheckList = () => {
    let s = localStorage.getItem(KEY_SELECT_CHECK_LIST)
    if (s) {
        return JSON.parse(s)
    }
    return s || []
}
